package Validaciones;

import javax.swing.*;

public final class ValidacionesPropietario {
    
    public static boolean validaCedula(String num, JTextField texto) {

        double res = num.length();
        String vacio = "" + num;//cambios hechos
        if (res > 13 || res < 6 || vacio.equals("") || !num.matches("[0-9]*")) {
            pintar(texto);
            return true;
        } else {
            texto.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 255, 0)));
            return false;
        }


    }
    
    public static boolean ValidacionesNomApe(String texto, JTextField campo) {

        String vacio = "" + texto;
        if (!texto.matches("[a-zA-ZÀ-ÖØ-öø-ÿ]+\\.?(( |\\-)[a-zA-ZÀ-ÖØ-öø-ÿ]+\\.?)*{4,30}")|| vacio.equals("")) {
            pintar(campo);
            return true;
        } else {
            campo.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 255, 0)));
            return false;
        }
    }

    public static boolean validaEdad(String num, JTextField texto) {
        
        String vacio = "" + num;
        
        if (vacio.equals("")) {
            pintar(texto);
            return true;
        } 
        
        else if(!num.matches("[0-9]{2}") || !num.matches("^(1[8-9])|(2[0-9])|(3[0-9])|(4[0-9])|(5[0-9])|(6[0-5])$")){
            pintar(texto);
            return true;
        }
            
            else {
            texto.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 255, 0)));
            return false;
        }
        
    }

    public static boolean validaTelefono(String num, JTextField texto) {

        double res = num.length();
        String vacio = "" + num;//cambios hechos
        if (res > 10 || res < 6 || vacio.equals("") || !num.matches("[0-9]*")) {
            pintar(texto);
            return true;
        } else {
            texto.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 255, 0)));
            return false;
        }


    }
    public static boolean validaEstado(int seleccion, JComboBox campo){
        if (seleccion ==0) {
            campo.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 0, 0)));
            return true;
        }else{
            return false;
        }
    }
    private static void pintar(JTextField txt) {
            txt.requestFocus();
            txt.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 0, 0)));
            txt.setSelectionStart(0);
            txt.setSelectionEnd(txt.getText().length());
    }
    
            
    
}